<?php

class CommonController extends Controller
{
	/**
	 * Declares class-based actions.
	 */
	public function actions()
	{
		return array(
			// captcha action renders the CAPTCHA image displayed on the contact page
			'captcha'=>array(
				'class'=>'CCaptchaAction',
				'backColor'=>0xFFFFFF,
			),
			// page action renders "static" pages stored under 'protected/views/site/pages'
			// They can be accessed via: index.php?r=site/page&view=FileName
			'page'=>array(
				'class'=>'CViewAction',
			),
		);
	}

	/**
	 * This is the default 'index' action that is invoked
	 * when an action is not explicitly requested by users.
	 */
	public function actionIndex()
	{
		// renders the view file 'protected/views/site/index.php'
		// using the default layout 'protected/views/layouts/main.php'
		$this->render('index');
	}

	/**
	 * This is the action to handle external exceptions.
	 */
	public function actionError()
	{
	    if($error=Yii::app()->errorHandler->error)
	    {
	    	if(Yii::app()->request->isAjaxRequest)
	    		echo $error['message'];
	    	else
	        	$this->render('error', $error);
	    }
	}
    
    function actionAjax_callfunction(){
        $objectfunction = Yii::app()->request->getPost('FUNC');
        $val_num = Yii::app()->request->getPost('VAL_NUM');

        $agrs = array();
        for($i=0; $i<$val_num; $i++){
            switch(Yii::app()->request->getPost('VAL'.$i)){
                case 'null':
                    $agrs[] = NULL;
                    break;
                case 'true':
                    $agrs[] = TRUE;
                    break;
                case 'false':
                    $agrs[] = FALSE;
                    break;
                default:
                    $agrs[] = Yii::app()->request->getPost('VAL'.$i);
            }
        }
        $val = new ValidatorComponent();
        echo $val->callFunction($objectfunction, $agrs);
        die();
    }

}